package com.oilsoft.shared.components
{
	import mx.graphics.SolidColorStroke;
	
	import spark.primitives.Graphic;
	import spark.primitives.Line;

	public class GraphicBoard_new extends Graphic
	{
		[Bindable]
		protected var alto:Number;
		[Bindable]
		protected var ancho:Number;
		
		public function GraphicBoard_new()
		{
		}
		
		
		override protected function createChildren():void
		{
			super.createChildren();
			trace("createChildren");
			trace("width: "+width+" height: "+height);
		}		
		
		override protected function commitProperties():void
		{
			super.commitProperties();
			trace("commitProperties");
			trace("width: "+width+" height: "+height);
		}
		override protected function measure():void
		{
			super.measure();
			
			trace("measure");
			trace("width: "+width+" height: "+height);
		}
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
			
		{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			trace("update display");
			trace("width: "+width+" height: "+height);
			alto=height;
			ancho=width;
			setGrid();
		}
		
		
		private function setGrid():void
		{
			
			var strokeBlack:SolidColorStroke = new SolidColorStroke();
			strokeBlack.color = 0x000000;
			strokeBlack.caps ="square";
			strokeBlack.joints="miter";
			
			var topLine:Line = new Line();
			topLine.xFrom=0;
			topLine.yFrom=0;
			topLine.xTo=ancho;
			topLine.yTo=0;
			topLine.stroke = strokeBlack;
			this.addElement(topLine);
			var bottonLine:Line =  new Line();
			bottonLine.xFrom=0;
			bottonLine.yFrom=alto;
			bottonLine.xTo=ancho;
			bottonLine.yTo=alto;
			bottonLine.stroke = strokeBlack;
			this.addElement(bottonLine);
			var leftLine:Line = new Line();
			leftLine.xFrom=0;
			leftLine.yFrom=0;
			leftLine.xTo=0;
			leftLine.yTo=alto;
			leftLine.stroke = strokeBlack;
			this.addElement(leftLine);
			var rightLine:Line = new Line();
			rightLine.xFrom=ancho;
			rightLine.yFrom=0;
			rightLine.xTo=ancho;
			rightLine.yTo=alto;
			rightLine.stroke = strokeBlack;
			this.addElement(rightLine);
			
			
			var stroke:SolidColorStroke = new SolidColorStroke();
			stroke.color = 0xDCDCDC;
			stroke.caps ="square";
			stroke.joints="miter";
			var i:int;
			for(i=1;i<this.height/25;i++){
				var lineHorizontal:Line = new Line();
				lineHorizontal.xFrom=0;
				lineHorizontal.xTo=ancho;
				lineHorizontal.yFrom=25*i;
				lineHorizontal.yTo=25*i;
				lineHorizontal.stroke  = stroke;
				this.addElement(lineHorizontal);
				
			} 
			for(i=1;i<this.width/25;i++){
				var lineVertical:Line = new Line();
				lineVertical.xFrom=25*i;
				lineVertical.xTo=25*i;
				lineVertical.yFrom=0;
				lineVertical.yTo=alto;
				lineVertical.stroke  = stroke;
				this.addElement(lineVertical);
			}
		}		
	}
}